# Contributor: G.J.R. Timmer <gjr.timmer@gmail.com>
# Maintainer: G.J.R. Timmer <gjr.timmer@gmail.com>
pkgname=pgtcl
_pkgname=Pgtcl
pkgver=2.1.0
pkgrel=1
pkgdesc="Tcl client side interface to PostgreSQL (libpgtcl)"
url="https://flightaware.github.io/Pgtcl/"
arch="all"
license="BSD-3-Clause"
makedepends="libpq-dev tcl-dev docbook2x"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/flightaware/$_pkgname/archive/v$pkgver.tar.gz"
builddir="$srcdir/$_pkgname-$pkgver"

prepare() {
	default_prepare || return 1

	cd "$builddir"
	sed -i -e 's/docbook2man/docbook2x-man/g' \
		-e 's|sh \./fix-fi\.sh man/\*||g' \
		doc/Makefile
}

build() {
	cd "$builddir"

	local x64_flags
	case "$CARCH" in
	aarch64 | x86_64) x64_flags="--enable-64bit";;
	esac

	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--mandir=/usr/share/man \
		--disable-rpath \
		--enable-threads \
		$x64_flags \
		|| return 1
	make || return 1
}

package() {
	cd "$builddir"

	make DESTDIR="$pkgdir" install || return 1
	make -C doc DESTDIR="$pkgdir" all || return 1

	# Remove empty directories.
	rmdir "$pkgdir"/usr/bin "$pkgdir"/usr/include
}

sha512sums="895f81548d5fde128b258cfb9cad732f539089a7c89bad08b7bc8a229d7f2ecdb9b31a374ddb3fb392ed3e20ba45cca47c2dccfa6ab86e617177f7021d08b3b3  pgtcl-2.1.0.tar.gz"
